/**
 * 跨页面常量，父页面与iframe页面保持一致
 */

//#region 全局常量、接口*******************************************************************************

/**
 * 两种游戏模式
 * @member {string} BALANCE - 均衡模式
 * @member {string} RANDOM - 随机模式
 */
enum GAME_MODE {
	BALANCE = 'balance',
	RANDOM = 'random',
}

/**
 * 玩家可选的势力
 * @member {string} QI - 齐
 * @member {string} CHU - 楚
 * @member {string} YAN - 燕
 * @member {string} HAN - 韩
 * @member {string} ZHAO - 赵
 * @member {string} WEI - 魏
 * @member {string} QIN -秦
 */
enum PLAYER_BLOC {
	QI = '齐',
	CHU = '楚',
	YAN = '燕',
	HAN = '韩',
	ZHAO = '赵',
	WEI = '魏',
	QIN = '秦',
}

/**
 * 固定势力
 * @member {string} ZHOU - 周
 * @member {string} WU - 吴
 * @member {string} YUE - 越
 * @member {string} BA - 巴
 * @member {string} SHU - 蜀
 * @member {string} LU - 鲁
 * @member {string} UI - 卫
 * @member {string} YIQU - 义渠
 * @member {string} LOUFAN - 楼烦
 * @member {string} DAI - 代
 * @member {string} LINHU - 林胡
 * @member {string} ZENG - 曾
 */
enum FIXED_BLOC {
	ZHOU = '周',
	WU = '吴',
	YUE = '越',
	BA = '巴',
	SHU = '蜀',
	LU = '鲁',
	UI = '卫',
	YIQU = '义渠',
	LOUFAN = '楼烦',
	DAI = '代',
	LINHU = '林胡',
	ZENG = '曾',
}

/**
 * 势力关系
 * @member {string} NONE - 中立
 * @member {string} FRIEND - 友好
 * @member {string} ALLY - 结盟
 * @member {string} ENEMY - 敌对
 */
enum BLOC_RELATIONSHIP {
	NONE = '中立',
	FRIEND = '友好',
	ALLY = '结盟',
	ENEMY = '敌对',
}

/**
 * 势力信息
 */
const BLOC_INFOS: IBlocInfo[] = [
	{ name: FIXED_BLOC.ZHOU, color: '#000000', },
	{ name: PLAYER_BLOC.QI, color: '#ffffff', },
	{ name: PLAYER_BLOC.CHU, color: '#00ff00', },
	{ name: PLAYER_BLOC.YAN, color: '#0000ff', },
	{ name: PLAYER_BLOC.HAN, color: '#ffff00', },
	{ name: PLAYER_BLOC.ZHAO, color: '#00ffff', },
	{ name: PLAYER_BLOC.WEI, color: '#ff00ff', },
	{ name: PLAYER_BLOC.QIN, color: '#ff0000', },

	{ name: FIXED_BLOC.WU, color: '#FFC0CB', },
	{ name: FIXED_BLOC.YUE, color: '#8B0000', },
	{ name: FIXED_BLOC.BA, color: '#FFA500', },
	{ name: FIXED_BLOC.SHU, color: '#90EE90', },
	{ name: FIXED_BLOC.LU, color: '#DAA520', },
	{ name: FIXED_BLOC.UI, color: '#00008B', },
	{ name: FIXED_BLOC.YIQU, color: '#87CEEB', },
	{ name: FIXED_BLOC.LOUFAN, color: '#7FFF00', },
	{ name: FIXED_BLOC.DAI, color: '#006400', },
	{ name: FIXED_BLOC.LINHU, color: '#808080', },
	{ name: FIXED_BLOC.ZENG, color: '#800080', },

];

/**
 * 可选对象类型
 * @member {string} COMMUNITY - 建筑
 * @member {string} TROOP - 部队
 */
enum SELECTABLE_TYPE {
	COMMUNITY = 'community',
	TROOP = 'troop',
}

//#endregion


//#region 全局接口************************************************************************************

/**
 * 势力信息接口
 */
interface IBlocInfo {
	name: PLAYER_BLOC | FIXED_BLOC,
	color: string
}

/**
 * 玩家信息
 * @property {string} id - 玩家id
 * @property {string} name - 玩家名称
 * @property {PLAYER_BLOC} bloc - 玩家所选的势力
 */
interface IPlayerInfo {
	id: string;
	name: string;
	bloc: PLAYER_BLOC;
}

//#endregion


//#region 全局方法************************************************************************************

/**
 * 获取势力信息
 * @param name 势力名称
 * @returns 势力信息
 */
const GetBlocInfo = (name: PLAYER_BLOC | FIXED_BLOC) => {
	return BLOC_INFOS.find(blocInfo => blocInfo.name === name);
};

//#endregion


//#region 父页面<->iframe 消息相关接口*****************************************************************

/**
 * 消息中心的消息类型
 * @member {string} IFRAME_READY - iframe加载完成
 * @member {string} SETUP - 初始化游戏
 * @member {string} GAME_START - 所有玩家相关游戏组件开始更新，对局开始
 * @member {string} GAME_OVER - 特定玩家被淘汰，对局继续进行
 * @member {string} GAME_END - 胜负决出，对局结束
 */
enum MESSAGE_HUB_TYPE {
	IFRAME_READY = 'iframeReady',
	SETUP = 'setup',
	GAME_READY = "gameReady",
	GAME_START = "gameStart",
	GAME_OVER = "gameOver",
	GAME_END = "gameEnd",
}

/**
 * 游戏初始化信息
 * @property {string} roomId - 房间id
 * @property {string} auth - 玩家授权信息
 * @property {IPlayerInfo} user - 用户信息
 * @property {Array<IPlayerInfo>} players - 其他玩家信息
 * @property {number} seed - 随机数种子
 */
interface IMessageSetup {
	roomId: string;
	auth: string;
	user: IPlayerInfo;
	players: Array<IPlayerInfo>;
	seed:number;
}

/**
 * 消息准备就绪接口
 * @property {IPlayerInfo} player - 准备就绪的玩家信息
 */
interface IMessageGameReady{
	player:IPlayerInfo;
}

//#endregion


//#region 联机相关接口*********************************************************************************

/**
 * 提交用户数据接口
 */
interface ISubmitUserData{}

/**
 * 分发玩家数据接口
 */
interface IDistributePlayerData{}

//#endregion


export {
	GAME_MODE,
	MESSAGE_HUB_TYPE,
	PLAYER_BLOC,
	FIXED_BLOC,
	BLOC_INFOS,
	GetBlocInfo,
	BLOC_RELATIONSHIP,
	SELECTABLE_TYPE,
};
export type {
	IBlocInfo,
	IMessageSetup,
	IPlayerInfo,
	ISubmitUserData,
	IDistributePlayerData,
	IMessageGameReady,
};